#pragma once

#include <linux/types.h>
#include <linux/bug.h>
#include <linux/errno.h>
#include <asm/thread_info.h>
#include <asm/current.h>

#include <linux/bitops.h>

struct task_struct;

/********************************************************************/

extern struct thread_info *task_thread_info(struct task_struct *task);
extern void init_thread_info(struct task_struct *task);

/****************************************************************/
extern struct thread_info * current_thread_info(void);

static inline int test_ti_thread_flag(struct thread_info *ti, int bit)
{
    return ti->flags & (1 << bit);
}

static __always_inline bool tif_test_bit(int bit)
{
	unsigned long flags = current_thread_info()->flags;

	return (flags & (1 << bit)) != 0;
}


static __always_inline bool tif_need_resched(void)
{
	return tif_test_bit(TIF_NEED_RESCHED);
}

/*
 * flag set/clear/test wrappers
 * - pass TIF_xxxx constants to these functions
 */

static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
{
	set_bit(flag, (unsigned long *)&ti->flags);
}

#define TIF_NEED_RESCHED_LAZY TIF_NEED_RESCHED

static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
{
	clear_bit(flag, (unsigned long *)&ti->flags);
}
